package com.orangelife.mobile.widget;

import com.curry.orangelife.mobile.R;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageButton;
import android.widget.PopupWindow;
import android.widget.TextView;

public class SelectPicPopupWindowView extends PopupWindow {

	//新浪微博按钮，朋友圈按钮，微信好友按钮，QQ按钮
	private ImageButton ibWeibo,ibPengyouquan,ibWeixin,ibQQ;
	//取消按钮
	private TextView tvCancel;
	private View mMenuView;

	public SelectPicPopupWindowView(Activity context,OnClickListener itemsOnClick) {
		super(context);
		LayoutInflater inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mMenuView = inflater.inflate(R.layout.dialog_share, null);
		ibPengyouquan = (ImageButton)mMenuView.findViewById(R.id.ib_pengyouquan);
		ibWeibo = (ImageButton)mMenuView.findViewById(R.id.ib_weibo);
		ibWeixin = (ImageButton)mMenuView.findViewById(R.id.ib_weixin);
		ibQQ = (ImageButton)mMenuView.findViewById(R.id.ib_qq);
		tvCancel = (TextView)mMenuView.findViewById(R.id.tv_cancel);
		//取消按钮
		tvCancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				//销毁弹出框
				dismiss();
			}
		});
		//设置按钮监听
		ibPengyouquan.setOnClickListener(itemsOnClick);
		ibWeibo.setOnClickListener(itemsOnClick);
		ibWeixin.setOnClickListener(itemsOnClick);
		ibQQ.setOnClickListener(itemsOnClick);
		//设置SelectPicPopupWindow的View
		this.setContentView(mMenuView);
		//设置SelectPicPopupWindow弹出窗体的宽
		this.setWidth(LayoutParams.FILL_PARENT);
		//设置SelectPicPopupWindow弹出窗体的高
		this.setHeight(LayoutParams.WRAP_CONTENT);
		//设置SelectPicPopupWindow弹出窗体可点击
		this.setFocusable(true);
		//设置SelectPicPopupWindow弹出窗体动画效果
		this.setAnimationStyle(R.style.AnimBottom);
		//实例化一个ColorDrawable颜色为半透明
		ColorDrawable dw = new ColorDrawable(0xb0000000);
		//设置SelectPicPopupWindow弹出窗体的背景
		this.setBackgroundDrawable(dw);
		//mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
		mMenuView.setOnTouchListener(new OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				
				int height = mMenuView.findViewById(R.id.pop_layout).getTop();
				int y=(int) event.getY();
				if(event.getAction()==MotionEvent.ACTION_UP){
					if(y<height){
						dismiss();
					}
				}				
				return true;
			}
		});

	}

}
